package com.studies.pc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.studies.pc.mapper.EvaluateInfoMapper;
import com.studies.pc.mapper.UndertakeOrgWithBlobsMapper;
import com.studies.pc.pojo.*;
import com.studies.pc.mapper.UndertakeOrgMapper;
import com.studies.pc.service.UndertakeOrgService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.studies.pc.query.ActivityQuery;
import com.studies.pc.vo.UndertakeOrgWithBlobsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 研学承办机构 服务实现类
 * </p>
 *
 * @author 研学活动后台
 * @since 2019-12-24
 */
@Service
public class UndertakeOrgServiceImpl extends ServiceImpl<UndertakeOrgMapper, UndertakeOrg> implements UndertakeOrgService {
        @Autowired
        private UndertakeOrgWithBlobsMapper undertakeOrgWithBlobsMapper;
        @Autowired
        private EvaluateInfoMapper evaluateInfoMapper;
    @Override
    public Map<String, Object> qryUndertakeOrgInfoActivityPage(Page<UndertakeOrg> pageParam,Integer id,String orgname) {
        QueryWrapper<UndertakeOrg> queryWrapper =new QueryWrapper<>();
        queryWrapper.orderByDesc("update_time");
        try{
            queryWrapper.orderByDesc("update_time");
            if (id != null) {
                //按id查询
                queryWrapper.eq("id",id);
            }
            if (orgname!=null){
                queryWrapper.like("orgname",orgname);
                //按承办机构查询
            }

        }catch (Exception e){
            e.printStackTrace();
        }finally {

            baseMapper.selectPage(pageParam, queryWrapper);
        }
            List<UndertakeOrg> records = pageParam.getRecords();
            long current = pageParam.getCurrent();
            long pages = pageParam.getPages();
            long size = pageParam.getSize();
            long total = pageParam.getTotal();
            boolean hasNext = pageParam.hasNext();
            boolean hasPrevious = pageParam.hasPrevious();


            Map<String, Object> map = new HashMap<String, Object>();
            map.put("items", records);
            map.put("current", current);
            map.put("pages", pages);
            map.put("size", size);
            map.put("total", total);
            map.put("hasNext", hasNext);
            map.put("hasPrevious", hasPrevious);

        return map;
    }

    @Override
    public IPage<Activity> selectPage(Page<Activity> activityPage, ActivityQuery activityVo) {
//        QueryWrapper<Activity> queryWrapper = new QueryWrapper<>();
//        try{
//            queryWrapper.orderByDesc("update_time");
//            if (activityVo.getBaseName() != null) {
//                //按name查询
//                queryWrapper.eq("base_name",activityVo.getBaseName());
//            }
//            if (activityVo.getUpdateTime()!=null){
//                queryWrapper.between("ser_start_time",activityVo.getSerStartTime(),activityVo.getSignEndTime());
//                //按时间查询
//            }
//
//        }catch (Exception e){
//            e.printStackTrace();
//        }finally {
//            return baseMapper.selectPage(activityPage,queryWrapper);
        return null;
        }

    @Override
    public UndertakeOrgWithBlobsVo qryUndertakeOrgInfo(Integer id) {
        UndertakeOrgWithBlobsVo undertakeOrgWithBlobsVo = undertakeOrgWithBlobsMapper.qryUndertakeOrgInfo(id);
        return undertakeOrgWithBlobsVo;
    }

    @Override
    public EvaluateInfo qryUndertakeOrgEvaluateInfo(Integer id) {
        EvaluateInfo evaluateInfo = evaluateInfoMapper.qryBaseEvaluateInfo(id);
        return evaluateInfo;
    }

    @Override
    public Map<String, Object> qryUndertakeOrgEvaluatePage(Page<EvaluateInfo> pageParam, Integer id) {
        QueryWrapper<BaseInfo> queryWrapper =new QueryWrapper<>();
        queryWrapper.orderByDesc("update_time");
        if (id!=null){
            queryWrapper.eq("undertake_org_id",id);
        }
        evaluateInfoMapper.qryBaseEvaluatePage(pageParam,id);
        List<EvaluateInfo> records =pageParam.getRecords();
        long current = pageParam.getCurrent();
        long pages = pageParam.getPages();
        long size = pageParam.getSize();
        long total = pageParam.getTotal();
        boolean hasNext = pageParam.hasNext();
        boolean hasPrevious = pageParam.hasPrevious();


        Map<String, Object> map = new HashMap<String, Object>();
        map.put("items", records);
        map.put("current", current);
        map.put("pages", pages);
        map.put("size", size);
        map.put("total", total);
        map.put("hasNext", hasNext);
        map.put("hasPrevious", hasPrevious);

        return map;
    }

}
